package com.ruoyi.web.controller.prt;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.prt.domain.PrtPrintLog;
import com.ruoyi.prt.domain.vo.PrtPrintLogVO;
import com.ruoyi.prt.service.IPrtPrintLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 打印记录Controller
 *
 * @author xiaobo Yan
 * @date 2021-03-31
 */
@RestController
@RequestMapping("/prt/printlog")
public class PrtPrintLogController extends BaseController
{
    @Autowired
    private IPrtPrintLogService prtPrintLogService;

    /**
     * 查询打印记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:printlog:list')")
    @GetMapping("/list")
    public TableDataInfo list(PrtPrintLog prtPrintLog)
    {
        startPage();
        List<PrtPrintLog> list = prtPrintLogService.selectPrtPrintLogList(prtPrintLog);
        return getDataTable(list);
    }

    /**
     * 导出打印记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:printlog:export')")
    @Log(title = "打印记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PrtPrintLog prtPrintLog)
    {
        List<PrtPrintLog> list = prtPrintLogService.selectPrtPrintLogList(prtPrintLog);
        ExcelUtil<PrtPrintLog> util = new ExcelUtil<PrtPrintLog>(PrtPrintLog.class);
        return util.exportExcel(list, "log");
    }

    /**
     * 获取打印记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:printlog:query')")
    @GetMapping(value = "/{printLogId}")
    public AjaxResult getInfo(@PathVariable("printLogId") String printLogId)
    {
        return AjaxResult.success(prtPrintLogService.selectPrtPrintLogById(printLogId));
    }

    /**
     * 新增打印记录
     */
    @PreAuthorize("@ss.hasPermi('system:printlog:add')")
    @Log(title = "打印记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PrtPrintLog prtPrintLog)
    {
        return toAjax(prtPrintLogService.insertPrtPrintLog(prtPrintLog));
    }

    /**
     * 修改打印记录
     */
    @PreAuthorize("@ss.hasPermi('system:printlog:edit')")
    @Log(title = "打印记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PrtPrintLog prtPrintLog)
    {
        return toAjax(prtPrintLogService.updatePrtPrintLog(prtPrintLog));
    }

    /**
     * 删除打印记录
     */
    @PreAuthorize("@ss.hasPermi('system:printlog:remove')")
    @Log(title = "打印记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{printLogIds}")
    public AjaxResult remove(@PathVariable String[] printLogIds)
    {
        return toAjax(prtPrintLogService.deletePrtPrintLogByIds(printLogIds));
    }

    /**
     * 获取打印记录详细信息
     */
    @GetMapping("/getPrintLog")
    @Log(title = "获取打印记录详细信息", businessType = BusinessType.SELECT)
    @PreAuthorize("@ss.hasRole('mobile')")
    public AjaxResult getPrintLog(PrtPrintLogVO printLogVO)
    {
        printLogVO.setUser(SecurityUtils.getUserId());
        return AjaxResult.success(prtPrintLogService.selectPrtPrintLogList(printLogVO));
    }
}
